﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BizAppFactory.Domain
{
    public partial class Aggregate
    {
        public Entity RootEntity
        {
            get
            {
                foreach (AggregateHasDomainClasses assoc in AggregateHasDomainClasses.GetLinksToDomainClasses(this))
                {
                    if (assoc.DomainClass is Entity && assoc.IsRoot)
                    {
                        return (Entity) assoc.DomainClass;       
                    }
                }

                throw new ApplicationException("No root entity was found in aggregate."); 
            }
        }
    }
}